<template>
    <div class="container-common homework-read-outline">
        <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item>作业评阅</el-breadcrumb-item>
            <el-breadcrumb-item>作业概览</el-breadcrumb-item>
        </el-breadcrumb>
        <el-table
                :data="tableData"
                border
                style="width: 100%">
            <el-table-column
                    prop="homework"
                    label="作业">
            </el-table-column>
            <el-table-column
                    prop="homework"
                    label="作业内容">
            </el-table-column>
            <el-table-column
                    prop="publishTime"
                    label="布置时间">
            </el-table-column>
            <el-table-column
                    prop="expireTime"
                    label="截止时间">
            </el-table-column>
            <el-table-column
                    label="操作"
                    width="240">
                <template slot-scope="scope">
                    <el-button
                            type="text"
                            size="large"
                            @click="handleRead(scope.row)">评阅</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
    import Api from '@utils/api';
    import {getDate} from '@utils/utils';
    import { mapGetters } from 'vuex';

    export default {
        name: "outline",
        data () {
            return {
                tableData: [],
                currentData: null
            }
        },
        computed: {
            ...mapGetters([
                'getCurrentCourseId'
            ])
        },
        methods: {
            handleRead (data) {
            this.currentData = data;
            this.$router.push({
                name: 'homeworkReadStudentSelect',
                params: {
                    task: data.id
                }
            })
            },
            getTableData () {
                Api({
                    method: 'get',
                    url: '/getHomeworkList',
                    params: {
                        course_id: this.getCurrentCourseId
                    }
                }).then(res => {
                    if (res.data && res.data.data && res.data.data.length) {
                        this.tableData = res.data.data.map(item => {
                            return {
                                id: item.task_id,
                                homework: item.task_name,
                                content: item.task_content,
                                publishTime: getDate(item.start_time),
                                expireTime: getDate(item.expire_time)
                            }
                        });
                    }
                })
            }
        },
        created () {
            this.getTableData();
        }
    }
</script>